package org.nokatag.accordion;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.NokaTag;
/**
 * <p>@Title </p>
 * <p>@Description top工具条</p>
 * <p>@Version 1.0.0</p>
 * <p>@author rebin</p>
 * <p>@date 2016年7月27日</p>
 * <p>xiefangjian@163.com</p>
 * <p>Copyright © Noka Laboratory.All Rights Reserved.</p>
 */
public class TopToolsTag extends  NokaTag{
	private static final long serialVersionUID = 1821039666968924995L;

	private String id = null;//div id
	private String style = null;//css文件地址
	private String direction="right";//方向 right | left
	private String onclick = null;//点击事件
	private String keepstate = null;//
	
	private  JspWriter jspOut =null;
	
	public int doStartTag()throws JspException{
		try{
			jspOut= pageContext.getOut();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			StringBuilder body = new StringBuilder();
			body.append(potjs(request));//js框架
			body.append(topToolsJS(request,style));//select js
			body.append("<div id=\""+id+"\" class=\"noka_top_menu\" style=\"float:"+direction+";\"></div>");
			body.append("<script type=\"text/javascript\">");
			//---------------显示树形菜单---------------------------
			body.append("Event.observe(document, 'dom:loaded', function() {");
			//--------------------------------------------------------------------
			body.append("var sfg"+id+" = {");
			body.append("id:'"+id+"',");//id
			if("true".equals(keepstate)){
				body.append("keepstate:true,");//
			}
			if(null!=onclick && onclick.trim().length()>0){
				body.append("onclick:"+onclick+",");
			}
			body.append("direction:'"+direction+"',");
			body.append("menus:");
			jspOut.write(body.toString());
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
			StringBuilder body = new StringBuilder();
			body.append("};");
			body.append("var nr"+id+" = new nokatop(sfg"+id+");");
			body.append("nr"+id+".show();");
			body.append("});");
			body.append("</script>");
			//---------------显示树形菜单---------------------------
			pageContext.getOut().write(body.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public String getDirection() {
		return direction;
	}
	public void setDirection(String direction) {
		this.direction = direction;
	}
	public String getOnclick() {
		return onclick;
	}
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
	public String getKeepstate() {
		return keepstate;
	}
	public void setKeepstate(String keepstate) {
		this.keepstate = keepstate;
	}
	
}
